package com.track;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.app.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Shader;
import android.os.Environment;
import android.content.*;


public class DDD extends Activity{
	
	private Menu mMenu;
	private Bitmap mBitmap;
	private Canvas canvas;
	private String[] images;
	public String currentImage;
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new DView(this));
           
	}
	 
	@Override
     public boolean onCreateOptionsMenu(Menu menu) {
       
         mMenu = menu;
         
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.ddd_page_menu, menu);      
         return true;
     }
	 
	private static class DView extends View {
		private BitmapShader mShader;
		private Paint mPaint;
		private Bitmap mBitmap;
		
		public DView (Context context) {
			super(context);
			  setFocusable(true);
	          setFocusableInTouchMode(true);
	       
            String path = Environment.getExternalStorageDirectory().getPath() + "/bsb_root/nyc.jpg";
            BitmapFactory.Options opts = new BitmapFactory.Options();
            Bitmap bm;

            opts.inJustDecodeBounds = true;    // this will request the bm
            opts.inSampleSize = 12;             // scaled down by 4
            bm = BitmapFactory.decodeFile(path);
            mBitmap = bm;
	        
	          //handleImageLoad("image.jpg");
		};
		@Override
		protected void onDraw(Canvas canvas) {
			
			canvas.drawColor(0xFF11CCDD);
			canvas.drawBitmap(mBitmap, 0, 0, null); 			
		}
		
		 private static Bitmap makeBitmapGrid() {
	            Bitmap bm = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888);
	            Canvas c = new Canvas(bm);
	            Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
	            p.setColor(Color.argb(255, 200, 200, 200));
	            p.setAlpha(0xFF);
	            c.drawRect(0, 0, 63, 63, p);
	            return bm;
	        }
	};
		

	
		public void handleImageLoad(String st) {
		 
		 String fPath = Environment.getExternalStorageDirectory().getPath()+"/bsd_root/" + st;
         BitmapFactory.Options opts = new BitmapFactory.Options();
         Bitmap bm;

         opts.inJustDecodeBounds = false;    // this will request the bm
         opts.inSampleSize = 4;             // scaled down by 4
         bm = BitmapFactory.decodeFile(fPath);
         mBitmap = bm;
	 };
	 
	 
	 
	 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

        
            case R.id.ddd_page_menu_img_access_0:
            	
            	handleImageLoad("image.jpg");
            	
            	return true;
            
            case R.id.ddd_page_menu_img_access_1:
            
            	handleImageLoad("image1.jpg");
            	return true;
            
            case R.id.ddd_page_menu_img_access_2:
            	
            	handleImageLoad("image2.jpg");
            	
            	return true;
            
            case R.id.ddd_page_menu_img_access_3:
            	
            	handleImageLoad("image3.jpg");
            	
            	return true;
            	
            default:
                
                break;
        }
        
        return false;
    }
	 

}
